/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <chrono>
#include "ParseParamVOneFive.h"
#include "common/JsonHelper.h"

using namespace std::chrono;
namespace backint {
std::vector<std::string> backupType {"backup", "restore", "inquire", "delete"};

std::vector<std::string> backupLevel {"COMPLETE", "DIFFERENTIAL", "INCREMENTAL", "METADATA", \
                                      "INITIALVOLUME", "CATALOG", "LOG"};
const mp_uint32 PARAM_STEP_SEP = 2;

uint32_t ParseParamVOneFive::ParamParse(int argc, char** argv)
{
    for (int i = 1; i < argc; i = i + PARAM_STEP_SEP) {
        if (i + 1 == argc) {
            break;
        }
        char *pszOp = argv[i];
        char *pszOpValue = argv[i + 1];
        if (_stricmp(pszOp, "-u") == 0) {
            m_stuParam.m_userId = pszOpValue;
        } else if (_stricmp(pszOp, "-f") == 0) {
            m_stuParam.m_funType = pszOpValue;
        } else if (_stricmp(pszOp, "-p") == 0) {
            m_stuParam.m_parFile = pszOpValue;
        } else if (_stricmp(pszOp, "-i") == 0) {
            m_stuParam.m_inputFile = pszOpValue;
        } else if (_stricmp(pszOp, "-o") == 0) {
            m_stuParam.m_outFile = pszOpValue;
        } else if (_stricmp(pszOp, "-t") == 0) {
            m_stuParam.m_backupType = pszOpValue;
        } else if (_stricmp(pszOp, "-v") == 0) {
            m_stuParam.m_version = std::stoi(pszOpValue);
        } else if (_stricmp(pszOp, "-V") == 0) {
            m_stuParam.m_versionDetail = std::stoi(pszOpValue);
        } else {
            ERRLOG("Error input data: %s\n", pszOpValue);
            continue;
        }
    }
    // gen BID
    int64_t curtimeMs = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
    m_stuParam.m_dtBackupId = std::to_string(curtimeMs);
    INFOLOG("m_backupID: %s", m_stuParam.m_dtBackupId);
    return SUCCESS;
}

ParseParamVOneFive::~ParseParamVOneFive()
{
}
}